<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="./css/font.css">
    <link rel="stylesheet" href="./css/xadmin.css">
    <script type="text/javascript" src="./js/jquery-2.1.0.js"></script>
    <script src="./lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="./js/Global.js"></script>
    <style>
        .wrap {
            padding: 20px;
        }


        .layui-input {
            border: 0px;
            padding: 0;
            height: 100%;
            width: 100%;
            text-align: center;
        }

        .btn {
            display: inline-block;

        }

        .layui-table td {
            padding: 0px;
            height: 30px;
            line-height: 0px;
            text-align: center;
        }

        .layui-table td {
            margin: 0px;
        }

        .layui-form-item {
            /* margin: 0px; */
            width: 100%;
            height: 100%;
        }

        .layui-form-item .layui-input-inline {
            width: 100%;
            /* margin: 0px !important; */
            height: 100%;
        }

        .layui-unselect {
            height: 40px;
        }

        .layui-select-title {
            height: 100%;
        }

        h3 {
            text-align: center;
        }
        .layui-form {
            display: inline-block;
            height: 24px;
        }

        .search {
            width: 200px;
            height: 38px;
            margin: 0 auto;
            display: inline-block;
            padding-top: 1px;

        }

        .search .layui-input {
            width: 200px;
            border: 1px solid #ccc;
        }

    </style>
</head>

<body>
    <div class="wrap">

            <div class="search">
                    <input class="layui-input ksdate" type="text" placeholder="开始日期">
                </div>
                <div class="layui-form">
                    <div class="layui-form-item">
                        <div class="layui-input-inline">
                            <select lay-filter="datesel" name="quiz2">
                                <option value="">请选时段</option>
                                <option value="0">一季度</option>
                                <option value="1">二季度</option>
                                <option value="2">三季度</option>
                                <option value="3">四季度</option>
                                <option value="4">上半年</option>
                                <option value="5">下半年</option>
                                <option value="6">本年度</option>
                                <option value="7">上年度</option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="search">
                    <input class="layui-input jsdate" type="text" placeholder="结束日期">
                </div>
                <div class="btn">
                    <button class="layui-btn layui-btn-normal" onclick="select()" >查询</button>
                </div>
        
        <table id="table" lay-filter="table" class="layui-table">
            <thead>
                <tr>
                    <th>序号</th>
                    <th>品名</th>
                    <th>品牌</th>
                    <th>规格</th>
                    <th>型号</th>
                    <th>产地</th>
                    <th>单位</th>
                    <th>状态</th>
                    <th>期初数量</th>
                    <th>本期入库</th>
                    <th>本期出库</th>
                    <th>期末数量</th>
                    <th>未税单价</th>
                    <th>含税单价</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody class="lists">
                
            </tbody>
        </table>
    </div>
</body>
<script>
	
    layui.use('table', function () {
        var table = layui.table;
    })
    layui.use('laydate', function () {
        var laydate = layui.laydate;

        //执行一个laydate实例
        laydate.render({
            elem: '.ksdate' //指定元素
        });
        laydate.render({
            elem: '.jsdate' //指定元素
        });
    });
    layui.use('form', function () {
        var form = layui.form
        form.on('select(datesel)', function (data) {
            let val = data.value
            let years = new Date().getFullYear()
            switch (val) {
                case '0':
                    $('.ksdate').val(`${years}-01-01`)
                    $('.jsdate').val(`${years}-03-31`)
                    break;
                case '1':
                    $('.ksdate').val(`${years}-04-01`)
                    $('.jsdate').val(`${years}-06-30`)
                    break;
                case '2':
                    $('.ksdate').val(`${years}-07-01`)
                    $('.jsdate').val(`${years}-09-30`)
                    break;
                case '3':
                    $('.ksdate').val(`${years}-10-01`)
                    $('.jsdate').val(`${years}-12-31`)
                    break;
                case '4':
                    $('.ksdate').val(`${years}-01-01`)
                    $('.jsdate').val(`${years}-06-30`)
                    break;
                case '5':
                    $('.ksdate').val(`${years}-07-01`)
                    $('.jsdate').val(`${years}-12-31`)
                    break;
                case '6':
                    $('.ksdate').val(`${years}-01-01`)
                    $('.jsdate').val(`${years}-12-31`)
                    break;
                    case '7':
                    $('.ksdate').val(`${years-1}-01-01`)
                    $('.jsdate').val(`${years-1}-12-31`)
                    break;
            }
        });
    })
    function goUrl(matId) {
        window.location.href = `./wuliaokucunxiangqing.html?custId=${loadUserInfo.customer.id}&startDate=${startDate}&endDate=${endDate}&matId=${matId}`
    }
    
    // 查询
    var startDate = ''
    var endDate = ''
    var custId=loadUserInfo.customer.id;
    function select () {
        // 开始
    startDate = $('.ksdate').val()
    endDate = $('.jsdate').val()
    $.ajax({
        url:`${API}/erpWarehouse/getWarehouseMaterielBycustId`,
        data:{
            custId:custId,
            startDate:startDate,
            endDate:endDate
        },
        type:'get',
        success: function (res) {
        	console.log(res);
            let str = ''
            let arr =res.data.reverse()
            $.each(arr,function (i) {
                let json = arr[i]
                str +=`<tr>
                    <td>${arr.length - i}</td>
                    <td>${json.materielName == null ? '' : json.materielName}</td>
                    <td>${json.materielBrand == null ? '' : json.materielBrand}</td>
                    <td>${json.materielSpecifications == null ? '' : json.materielSpecifications}</td>
                    <td>${json.materielModel == null ? '' : json.materielModel}</td>
                    <td>${json.materielPlace == null ? '' : json.materielPlace}</td>
                    <td>${json.materielUnit == null ? '' : json.materielUnit}</td>
                    <td>${json.materielBmaterielStaterand == null ? '' : json.materielBmaterielStaterand}</td>
                    <td>${json.materielNumber == null ? '' : json.materielNumber}</td>
                    <td>${json.inMatNum == null ? '' : json.inMatNum}</td>
                    <td>${json.outMatNum == null ? '' : json.outMatNum}</td>
                    <td>${json.matNum == null ? '' : json.matNum}</td>
                    <td>${json.materielTax == null ? '' : json.materielTax}</td>
                    <td>${json.materielNotax == null ? '' : json.materielNotax}</td>
                    <td>
                        <div class="layui-btn layui-btn-xs" onclick="goUrl(${json.id})">查看</div>
                    </td>
                </tr>`
            })
            $('.lists').html(str)

        },
        error: function () {
            alert('系统错误，请稍后重试！')
        }
    })
    }
    select()
</script>

</html>